<template>
  <div>
    <div ref="qrCodeUrl" class="qrcode"></div>
  </div>
</template>

<script>
import QRCode from 'qrcodejs2'
export default {
  name: "GenerateQRCode",
  props: {
    value: {
      type: [String, Number],
      default: "",
    },
    width: {
      type: [String, Number],
      default: "100",
    },
    height: {
      type: [String, Number],
      default: "100",
    }
  },
  data() {
    return {};
  },
  watch: {
    value: function() {
      this.creatQrCode();
    }

  },
  mounted() {
  },

  methods: {
    creatQrCode() {
      var that = this
      setTimeout(() => {
        new QRCode(that.$refs.qrCodeUrl, {
          text: this.value, // 需要转换为二维码的内容
          width: this.width,
          height: this.height,
          colorDark: '#000000',
          colorLight: '#ffffff',
          correctLevel: QRCode.CorrectLevel.H
        })
      }, 100)
    },
  },
};
</script>

<style scoped="scoped" lang="scss">
</style>
